﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.Library;
using System.Data;
using IHISCETeim.BLL;
using IHISCETeim.Model;

namespace IHISCETeim.Web.MachineSys.MacModel
{
    public partial class OFactoryRenovationList : EasyUIPageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看, Permission.修改, Permission.新增, Permission.删除 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "OFactoryRenovationList";
            }
        }


        #region 属性 (查询条件)

        /// <summary>
        /// 排序字段 值为 id
        /// </summary>
        protected override string orderField
        {
            get
            {
                return string.IsNullOrEmpty(base.orderField) ? "id" : base.orderField;
            }
        }
        /// <summary>
        ///  排序方式 desc或 asc
        /// </summary>
        protected override string orderDirection
        {
            get
            {
                return string.IsNullOrEmpty(base.orderDirection) ? "DESC" : base.orderDirection;
            }
        }


        protected override string SQLSort
        {
            get
            {
                return (orderField + " " + orderDirection);
            }
        }

        [QueryColumnName(), QueryOperator(QueryOperatorsEnum.包含)]
        public string DocNum
        {
            get
            {
                return GetRequestValue<string>("DocNum", "");

            }

        }
       
        [QueryColumnName(), QueryOperator(QueryOperatorsEnum.包含)]
        public string AgentName
        {
            get
            {
                return GetRequestValue<string>("AgentName", "");
            }
        }

        [QueryColumnName(), QueryOperator(QueryOperatorsEnum.包含)]
        public string SerialNumber
        {
            get
            {
                return GetRequestValue<string>("SerialNumber", "");
            }
        }
        [QueryColumnName(), QueryOperator(QueryOperatorsEnum.等于)]
        public string MachineProperty
        {
            get
            {
                return GetRequestValue<string>("MachineProperty", "");
            }
        }
        /// <summary>
        /// 只是显示未完成的
        /// </summary>
        public string OnlyWeiWC
        {
            get
            {
                return GetRequestValue<string>("OnlyWeiWC", "");
            }
        }
        public string OnlyHGWXS
        {
            get
            {
                return GetRequestValue<string>("OnlyHGWXS", "");
            }
        }
        
        #endregion

        protected string GetSql()
        {
            string sqlwhere = QueryFiledHelper.GetSqlWhere(this);
            string OnlyWeiWCSql = "";
            if (!string.IsNullOrEmpty(OnlyWeiWC))
            {
                if (!string.IsNullOrEmpty(sqlwhere))
                    sqlwhere += " and CompDate is null ";
                else
                    sqlwhere = " CompDate is null ";
            }

            if (!string.IsNullOrEmpty(OnlyHGWXS))
            {
                if (!string.IsNullOrEmpty(sqlwhere))
                    sqlwhere += " and MachineProperty='回购车' and  NewContractNo is null";
                else
                    sqlwhere = " MachineProperty='回购车' and  NewContractNo is null ";
            }
           
            return sqlwhere;
        }


        protected override string query()
        {
            string sqlwhere = GetSql();
            DataTableCollection dts = OFactoryRenovationController.GetPagination(sqlwhere, pageNum, numPerPage, SQLSort, ref TotalCount);
            return ToDataGridJson(dts[0], TotalCount, dts[1]).ToString();
        }

        protected override string delrow()
        {
            if (base.User.UserType != 1)
                return "";

            int id = GetRequestValue<int>("ID", 0);
            bool r = OFactoryRenovationController.Delete(id);
            if (r)
                SuccessJson("已成功删除", this.DWZRef);
            else
                ErrorJson("删除失败");

            return "";
        }
    }
}